<?php
define('IN_QY',true);
require("include/common.inc.php");

// 海淘首页商品列表
//首页api
$serh=$_GET['sname'];
$sidd=$_GET['sidd'];


//$reslut = "select count(*) as a from tbl_taospp where state=1 and concat(chtitle,enbrand) LIKE '%$serh%' and goodstype<4 ";		


//mamabang

$reslut = "select count(*) as a from tbl_taospp where state=1 and concat(chtitle,enbrand) LIKE '%$serh%' and goodstype<4 ";

$query_reslut = mysql_query($reslut);
$row_reslut=mysql_fetch_array($query_reslut);
$count=$row_reslut['a'];
//页面数量
$page_size=5;
//总页数
$page_count = ceil($count/$page_size);

//第几页
$page=$_GET['page'];
if($page==''){
  $page=1;
}
$last=$page-1;//上一页
$next=$page+1;//下一页

if($page>$page_count){

    $arr = 0;
    echo $arr;
    exit;

}

//页面起始条数
$offset=$page_size*($page-1);

// if($sidd=="1"){
// $sql = "select * from tbl_taospp  where state=1 and goodstype<4 and  concat(chtitle,enbrand) LIKE '%$serh%'  limit $offset,$page_size";	
	
// }
// if($sidd=="2"){
// $sql = "select * from tbl_taospp  where state=1 and goodstype<4 and  concat(chtitle,enbrand) LIKE '%$serh%' order by id desc  limit $offset,$page_size";	
	
// }
// if($sidd=="3"){
// $sql = "select * from tbl_taospp  where state=1 and goodstype<4 and  concat(chtitle,enbrand) LIKE '%$serh%' order by soldnum desc  limit $offset,$page_size";	
	
// }
// if($sidd=="4"){
	
// $sql = "select * from tbl_taospp  where state=1 and goodstype<4 and  concat(chtitle,enbrand) LIKE '%$serh%' order by zswprice desc  limit $offset,$page_size";	
// }



//mamabang
if($sidd=="1"){
$sql = "select * from tbl_taospp  where state=1 and goodstype<4  and   concat(chtitle,enbrand) LIKE '%$serh%'  limit $offset,$page_size";	
	
}
if($sidd=="2"){
$sql = "select * from tbl_taospp  where state=1 and goodstype<4  and  concat(chtitle,enbrand) LIKE '%$serh%' order by id desc  limit $offset,$page_size";	
	
}
if($sidd=="3"){
$sql = "select * from tbl_taospp  where state=1 and goodstype<4 and  concat(chtitle,enbrand) LIKE '%$serh%' order by soldnum desc  limit $offset,$page_size";	
	
}
if($sidd=="4"){
	
$sql = "select * from tbl_taospp  where state=1 and goodstype<4 and  concat(chtitle,enbrand) LIKE '%$serh%' order by zswprice desc  limit $offset,$page_size";	
}






$query = mysql_query($sql);

class Stu{  
//app首页商品表，字段解释
    public $id;  
    public $img; 
    public $title;  
    public $price; 
    public $enbrand;
    public $tximg;
    public $txname;	
    public $vip_price;	
    public $goodstype;		
} 
while($row=mysql_fetch_object($query)){   
   	$imgg=$row->img; 
   	$img=explode(',',$imgg);		
	$rowg=$img['0'];
	$fd=$row->cat_id; 	
	
	$fdd=$row->ggunit; 
	$sqljnamee = "SELECT DISTINCT * from tbl_user  where id='".$fdd."' ";
    $queryjnamee=mysql_query($sqljnamee);
    $rowjnamee=mysql_fetch_array($queryjnamee);	
	
    $s=new Stu();
    $s->id=$row->id;  
    $s->title=$row->chtitle;  
    $s->price=$row->zswprice;  
    $s->enbrand=$row->enbrand;  
    $s->vip_price=$row->vip_price;  
    $s->goodstype=$row->goodstype;  	
	$s->img=$rowg; 
    $s->tximg=$rowjnamee['username'];   
    $s->txname=$rowjnamee['shuyu']; 	
	
	$arr[]=$s;
} 
echo json_encode(array('data'=>$arr)); 

//
